<script lang="ts" setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { dofinishregister } from '../../api/user'
import { showToast } from 'vant';

const router = useRouter()
const password = ref('')
const password2 = ref('')



const flag = computed(() => {
    return password.value != password2.value || password.value.length == 0
})



function onSubmit() {

    dofinishregister({
        tel: localStorage.getItem('tel'),
        password: password.value
    }).then(res => {
        // console.log(res);
        if (res.data.code == '200') {
            // 成功
            showToast('恭喜您注册成功💐💐💐')

            // 删除本地存的手机号
            localStorage.removeItem('tel')

            router.push('/login')
        } else {
            // 失败
            showToast('温馨提示：' + res.data.message)
        }
    })

    // router.push('/login')

}
</script>
<template>
    <div class="content" style="padding: 45px 0;">

        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="password" name="" label="密码" placeholder="请输入密码"
                    :rules="[{ required: true, message: '请填写密码' }]" />

                <van-field v-model="password2" name="" label="确认密码" placeholder="请再次输入密码"
                    :rules="[{ required: true, message: '请再次填写密码' }]" />
            </van-cell-group>
            <div style="margin: 26px;">
                <van-button :disabled="flag" round block type="primary" color="#f66" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
    </div>
</template>